package exercise5;
import javax.swing.JOptionPane;
import java.util.*;
public class DiagonalOfPlus {
	public static int[][] addMatrix(int[][] m1, int[][] m2) {
		int[][] m3=new int[m1.length][m1.length];
		if(m1.length!=m2.length) {
			System.out.println("对不起您输入的两个数字维数不对应");
		}
		else {
			for(int i=0;i<m3.length;i++) {
				for(int j=0;j<m3.length;j++) {
					m3[i][j]=m1[i][j]+m2[i][j];
				}
			}
			int count=0;
			System.out.println("The addition of the matrices is");
			for(int i=0;i<m3.length;i++) {
				count++;
				for(int j=0;j<m3.length;j++) {
					System.out.print(m1[i][j]+" ");
				}
				if(count==m3.length/2+1) {
					System.out.print("    +    ");
				}
				else {
					System.out.print("         ");
				}
				for(int k=0;k<m3.length;k++) {
					System.out.print(m2[i][k]+" ");
				}
				if(count==m3.length/2+1) {
					System.out.print("    =    ");
				}
				else {
					System.out.print("         ");
				}
				for(int k=0;k<m3.length;k++) {
					System.out.print(m3[i][k]+" ");
				}
				System.out.print("\n");
			}	
		}

		return m1;
	}
}
